package jzoffer;

import java.util.Stack;

/**
 * @author dengxin
 * @create 2020/6/11 8:49 下午
 * 用两个栈实现一个队列，完成队列的Push和Pop操作，队列中元素为int类型
 */
@SuppressWarnings("all")
public class jz5 {

    Stack<Integer> stack1 = new Stack<>();
    Stack<Integer> stack2 = new Stack<>();

    public void push(int node) {
        stack1.push(node);
    }

    public int pop() throws Exception {
        if (stack1.empty()) {
            throw new Exception("empty queue!");
        }
        while (!stack1.empty()) {
            stack2.push(stack1.pop());
        }
        int result = stack2.pop();
        while (!stack2.empty()) {
            stack1.push(stack2.pop());
        }
        return result;
    }
}
